package com.qf.bootmr.controller;

import com.qf.bootmr.entity.Pic;
import com.qf.bootmr.result.R;
import com.qf.bootmr.service.PicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * (Pic)表控制层
 *
 * @author makejava
 * @since 2021-05-26 10:24:35
 */
@Api(value = "PicAPI")
@RestController
@RequestMapping("pic")
public class PicController {
    /**
     * 服务对象
     */
    @Resource
    private PicService picService;

    /**
     * 通过主键查询单条数据
     * 非常的v
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "selectOne",notes = "通过图片id获取到对应图片信息")
    @ApiImplicitParam(name = "id",value = "图片的id",dataType = "int",required = true)
    @GetMapping("selectOne/{id}")
    public Pic selectOne(@PathVariable("id") Integer id) {
        return this.picService.queryById(id);
    }

    @ApiOperation(value = "queryByType",notes = "通过图片id获取到对应图片信息")
    @ApiImplicitParam(name = "id",value = "图片的id",dataType = "int",required = true)
    @GetMapping(value = "/queryByType/{type}")
    public R queryByType(@PathVariable("type") String type){
        Pic pic = new Pic();
        pic.setType(type);
        List<Pic> picList = picService.queryAll(pic);
        System.out.println(picList);
        return R.ok().data(picList);
    }


    @ApiOperation(value = "queryByType",notes = "通过图片id获取到对应图片信息")
    @ApiImplicitParam(name = "id",value = "图片的id",dataType = "int",required = true)
    @GetMapping(value = "/queryAll")
    public R queryByType(){
        Pic pic = new Pic();
        List<Pic> picList = picService.queryAll(pic);
        System.out.println(picList);
        return R.ok().data(picList);
    }

    @ApiOperation(value = "queryByTitle",notes = "通过title查询图片信息")
    @GetMapping(value = "/queryByTitle/{title}")
    public R queryByTitle(@PathVariable String title){
        List<Pic> titles = picService.queryByTitle(title);
        return R.ok().data(titles);
    }
}
